package ru.chaykin.util;

import java.io.File;

public abstract class FileNameFormatHelper {
	
	private static final String MIF_Ext = "mif";
	
	public static String getMIDFileName(String mifFileName) {
		int sepPos = mifFileName.lastIndexOf(File.separator);
		int extPos = mifFileName.lastIndexOf(".");
		if (sepPos > extPos) {
			return mifFileName + ".MID";
		}
		else {
			char[] chars = mifFileName.toCharArray();
			chars[chars.length - 1] = Character.isLowerCase(chars[chars.length - 1]) ? 'd' : 'D';
			return new String(chars);
		}
	}
	
	public static boolean isMIFExtention(String fileName) {
		return getFileExtention(fileName).equalsIgnoreCase(MIF_Ext);
	}
	
	public static String getFileExtention(String fileName) {
		int sepPos = fileName.lastIndexOf(File.separator);
		String nameAndExt = fileName.substring(sepPos + 1, fileName.length());
		int dotPos = nameAndExt.lastIndexOf(".");
		return dotPos == -1 ? "" : nameAndExt.substring(dotPos + 1);
	}
}
